//
//  HandTool.m
//  LightMoxibustion
//
//  Created by flyliu on 2021/11/23.
//

#import "HandTool.h"

@implementation HandTool

//获取当前显示的控制器
+ (UIViewController *)getCurrentVC {
    
    UIViewController *result = nil;
    
    UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    
    do {
        if ([rootVC isKindOfClass:[UINavigationController class]]) {
            UINavigationController *navi = (UINavigationController *)rootVC;
            UIViewController *vc = [navi.viewControllers lastObject];
            result = vc;
            rootVC = vc.presentedViewController;
            continue;
        } else if([rootVC isKindOfClass:[UITabBarController class]]) {
            UITabBarController *tab = (UITabBarController *)rootVC;
            result = tab;
            rootVC = [tab.viewControllers objectAtIndex:tab.selectedIndex];
            continue;
        } else if([rootVC isKindOfClass:[UIViewController class]]) {
            result = rootVC;
            rootVC = nil;
        }
    } while (rootVC != nil);
    
    return result;
}

+ (int)scoreWithsubWeather:(NSString *)subWeather{
    if ([subWeather isEqualToString:@"🌧"]) {
        return 0;
    }else if ([subWeather isEqualToString:@"⛅️"]){
        return 1;
    }else{
        return 2;
    }
}

+ (int)scoreWithweather:(NSString *)weather{
    
    if (weather.length != 6) {
        return 0;
    }
    
    int total = 0;
    total = total + [self scoreWithsubWeather:[weather substringWithRange:NSMakeRange(0, 2)]];
    total = total + [self scoreWithsubWeather:[weather substringWithRange:NSMakeRange(2, 2)]];
    total = total + [self scoreWithsubWeather:[weather substringWithRange:NSMakeRange(4, 2)]];
    return total;
   
}

+ (UIColor *)getThemeColorWithWeather:(NSString *)weather{
    if (weather.length != 6) {
        return Color_Theme;
    }
    
    int total = [self scoreWithweather:weather];
    
    switch (total) {
        case 0:
        {
            return  [UIColor colorWithRed:0/255.0 green:255 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
        case 1:
        {
            return  [UIColor colorWithRed:125/255.0 green:255 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
        case 2:
        {
            return  [UIColor colorWithRed:170/255.0 green:255 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
        case 3:
        {
            return  [UIColor colorWithRed:255/255.0 green:255 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
        case 4:
        {
            return  [UIColor colorWithRed:255/255.0 green:170 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
        case 5:
        {
            return  [UIColor colorWithRed:255/255.0 green:85 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
        case 6:
        {
            return  [UIColor colorWithRed:255/255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
            
            
        default:
        {
            return  [UIColor colorWithRed:255/255.0 green:0 / 255.0 blue:0 / 255.0 alpha:1];
        }
            break;
    }
}

@end
